import redis
client = redis.StrictRedis(password='123456')
# # 添加列表元素
# client.lpush('nums', 1, 2, 3, 4, 5, 6, 7, 8)
# client.rpush('nums', 6)
# 获取数据
e = client.lrange('nums', 0, 20)
print(e)
# 获取列表长度
l = client.llen('nums')
print(l)
# 获取指定索引的元素
r = client.lindex('nums', 6)
print(r)
r = client.lset('nums', 5, 100)
print(r, e, l)
# # 头部删除一个
# r = client.lpop('nums')
# print(r, e, l)
# # 尾部删除一个
# r = client.rpop('nums')
# print(r, e, l)
# # 根据列表的值删除元素
# r = client.lrem('nums', 1, 100)
# print(r, e)
# # 列表切片
# r = client.ltrim('nums', 0, 5)
# print(r, e)
client.close()
